package com.codeczx.mygeeknews.zhihu;

import com.codeczx.mygeeknews.Api;
import com.codeczx.mygeeknews.DailyListBean;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;


/**
 * Created by win10 on 2017/7/2.
 */

public class DailyPresenter implements DailyContract.Presenter {

    private DailyContract.View view;

    @Override
    public void attachView(DailyContract.View view) {
        this.view = view;
    }

    @Override
    public void detachView() {
        this.view = null;
    }

    @Override
    public void getDailyData() {
        Api.getInstance().service.getDailyList()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<DailyListBean>() {
                    @Override
                    public void accept(@NonNull DailyListBean dailyListBean) throws Exception {
                        view.showContent(dailyListBean);
                    }
                });
    }
}
